二、特性
package main
import (
"fmt"
)
func main() {
x, y := 1, 22
op := func(x, y int) int {
return x + y
}
fmt.Println(op(x,y))
}
https://play.golang.org/p/pNhWS7ITBfl
package main
import (
"fmt"
)
type operate func(x, y int) int
//Sum和operate的宣告方式一致
func Sum(a, b int) int {
return a + b
}
func main() {
x, y := 1, 22
var op operate
op = Sum //把Sum函數賦給operate類型的變數op
fmt.Println(op(x,y))
}
https://play.golang.org/p/8VdeAH3X6S7